package dnl.toolbox.dto;

import dnl.toolbox.lang.Args;

/**
 * A symmetric key for a pair of classes.
 * 
 * @author daniel
 * 
 */
public class ConverterKey {

	private Class<?> classA;
	private Class<?> classB;

	public ConverterKey(Class<?> classA, Class<?> classB) {
		Args.assertNotNull(classA);
		Args.assertNotNull(classB);
		this.classA = classA;
		this.classB = classB;
	}

	public Class<?> getClassA() {
		return classA;
	}

	public void setClassA(Class<?> classA) {
		this.classA = classA;
	}

	public Class<?> getClassB() {
		return classB;
	}

	public void setClassB(Class<?> classB) {
		this.classB = classB;
	}

	@Override
	public int hashCode() {
		int h = 0;
		h += classA.getName().hashCode();
		h += classB.getName().hashCode();
		return h;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final ConverterKey other = (ConverterKey) obj;
		String classAName = classA.getName();
		String classBName = classB.getName();
		String otherAName = other.classA.getName();
		String otherBName = other.classB.getName();

		return (classAName.equals(otherAName) && classBName.equals(otherBName))
				|| (classAName.equals(otherBName) && classBName
						.equals(otherAName));

	}

}
